package com.thrd.taiexhibition.ui;

import android.content.Context;
import android.graphics.Color;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.thrd.taiexhibition.R;
import com.thrd.taiexhibition.bean.LabelLink;

import java.util.List;

/**
 * 大家都在看标签
 * @author: ${唐杰}
 * @date: 2021/3/26
 */
public class LinearLabelView extends LinearLayout {
    public LinearLabelView(Context context) {
        this(context,null);
    }

    public LinearLabelView(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs,0);
    }

    public LinearLabelView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        setOrientation(HORIZONTAL);
        setGravity(Gravity.CENTER_VERTICAL);

    }

    public  void   setData(List<LabelLink>  stringList){
        removeAllViews();
        for (final LabelLink s:stringList){
            TextView textView=new TextView(getContext());
            textView.setText(s.getLabelname());
            textView.setBackground(getResources().getDrawable(R.drawable.linear_item_bg));
            textView.setTextColor(Color.BLACK);
            textView.setTextSize(10);
            textView.setPadding(getResources().getDimensionPixelSize(R.dimen.qb_px_8),getResources().getDimensionPixelSize(R.dimen.qb_px_2),getResources().getDimensionPixelSize(R.dimen.qb_px_8),getResources().getDimensionPixelSize(R.dimen.qb_px_2));
            LinearLayout.LayoutParams layoutParams=new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
            layoutParams.setMargins(getResources().getDimensionPixelSize(R.dimen.qb_px_5),0,getResources().getDimensionPixelSize(R.dimen.qb_px_5),0);
            layoutParams.gravity= Gravity.CENTER;
            textView.setLayoutParams(layoutParams);
            textView.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    if(onLinearLabel!=null) onLinearLabel.setOnLinearLabel(s);
                }
            });
            addView(textView);
        }

    }

    private OnLinearLabel onLinearLabel;

    public OnLinearLabel getOnLinearLabel() {
        return onLinearLabel;
    }

    public void setOnLinearLabel(OnLinearLabel onLinearLabel) {
        this.onLinearLabel = onLinearLabel;
    }

    public interface OnLinearLabel{
        void setOnLinearLabel(LabelLink mLinearLabel);
    }
}
